home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / game / shoot / Orbit_src.lha / Orbit / source / orbit.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-04  |  20.3 KB  |  877 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #define VERSION "1.01"
  23.  
  24. #ifdef AMIGA
  25. #define AMIGA_VERSION "0.6"
  26. #define AMIGA_DATE    "04.07.2000"
  27. #endif
  28.  
  29. #include <stdio.h>
  30. #include <time.h>
  31. #include <math.h>
  32. #include <string.h>
  33. #include <sys/types.h>
  34.  
  35. #ifndef WIN32
  36. #include <stdlib.h>
  37. #endif
  38.  
  39. #ifdef WIN32
  40. #include <windows.h>
  41. #include <GL/gl.h>
  42. #include <GL/glu.h>
  43. #include </mesa/mesa-3.0/include/GL/glut.h>
  44. #include <winsock.h>
  45. #else
  46. #include <GL/gl.h>
  47. #include <GL/glu.h>
  48. #include <GL/glut.h>
  49. #endif
  50.  
  51. #ifdef AMIGA
  52. #include <libraries/lucyplay.h>
  53. #include <clib/lucyplay_protos.h>
  54. extern struct Library *LucyPlayBase;
  55. #endif
  56.  
  57. #ifdef ALLOCATE
  58. #define EXTERN
  59. #else
  60. #define EXTERN extern
  61. #endif
  62.  
  63. #ifdef WIN32
  64. #pragma warning(disable:4013) /* blah() undefined; assuming extern returning int */
  65. #pragma warning(disable:4033) /* blah() must return a value */
  66. #pragma warning(disable:4716) /* blah() must return a value */
  67. #endif
  68.  
  69. /* THETA is rate of rotation in radians per second */
  70. #define THETA (1.6)
  71.  
  72. /* Maximum change in velocity, per second, at full throttle */
  73. #define DELTAV (0.2)
  74.  
  75. /* Coefficient of current velocity added to acceleration under warp speed */
  76. #define WARP_COEFF (0.2)
  77.  
  78. /* Throttle limits for arcade mode, in kps */
  79. #define MAX_THROTTLE (10000.0 / KM_TO_UNITS1)
  80. #define MAX_WARP_THROTTLE (1000000.0 / KM_TO_UNITS1)
  81.  
  82. #define SCREENWIDTH (640)
  83. #define SCREENHEIGHT (480)
  84.  
  85. void DrawScene(void);
  86. void Reshape(int, int);
  87. void MovePlayer();
  88. double Dist2();
  89. double rnd();
  90. double Time();
  91. double Theta();
  92. double Dotp();
  93. double Mag();
  94. double Mag2();
  95. void Log (char *fmt, ...);
  96. void Mprint (char *msg, ...);
  97. void Cprint (char *c, ...);
  98. void DoConnect (void);
  99. void DoChat (void);
  100. void DoDrop (void);
  101. void DoLoad (void);
  102. void DoName (void);
  103.  
  104. EXTERN int ScreenWidth, ScreenHeight;
  105. EXTERN double fov;
  106.  
  107. /* Stuff to remember about the player */
  108. #define FLIGHT_NEWTONIAN (0)
  109. #define FLIGHT_ARCADE (1)
  110. EXTERN struct
  111. {
  112.   char name[64];  /* Player name */
  113.   char model[128]; /* Ship model (for multiplayer) */
  114.   double pos[3];  /* Player position */
  115.   double up[3];  /* Camera "up" vector */
  116.   double view[3];  /* Viewing direction */
  117.   double right[3]; /* Right-hand vector */
  118.  
  119.   double move_forward, move_backward,
  120.   move_up, move_down,
  121.   move_pitchleft, move_pitchright,
  122.   move_left, move_right; /* Motion */
  123.  
  124.   int flightmodel; /* Newtonian or arcade */
  125.  
  126.   double vel[3];  /* Player's velocity */
  127.   double throttle; /* Throttle for arcade mode */
  128.   int score;   /* Player's score */
  129.  
  130.   double shields;  /* Strenth of shields */
  131.   double maxshields; /* Maximum shields */
  132.   int weapon;   /* Current weapon */
  133.   double msl_idle; /* Weapon idle time */
  134.   int waypoint;  /* Selected waypoint */
  135.   double dead_timer; /* Time to die */
  136.   int still;   /* Not changing orientation */
  137.   int viewlock;  /* True if view locked on something */
  138. }
  139. player;
  140.  
  141. /* Clipping planes */
  142. EXTERN double clipnear;
  143. EXTERN double clipfar;
  144.  
  145. #define DEAD_TIME (5.0)
  146.  
  147. EXTERN int vulnerable; /* If player can be killed */
  148.  
  149. EXTERN int joy_available; /* True if we have a joystick */
  150. /*
  151.  *  Joystick values:
  152.  *
  153.  *  x,y - stick position
  154.  *  r   - stick twist
  155.  *  z   - throttle position
  156.  */
  157. EXTERN double joy_x, joy_xmin, joy_xmax,
  158. joy_y, joy_ymin, joy_ymax,
  159. joy_r, joy_rmin, joy_rmax,
  160. joy_z, joy_zmin, joy_zmax;
  161. EXTERN int joy_buttons;  /* State of joystick buttons */
  162. EXTERN int joy_throttle;  /* True to use joystick throttle */
  163. EXTERN double deadzone;   /* Joystick dead zone */
  164.  
  165. #define DEADZONE (0.1) /* Joystick dead zone */
  166.  
  167. EXTERN int mouse_x, mouse_y; /* Stuff for mouse */
  168. EXTERN int last_mouse_x, last_mouse_y;
  169.  
  170. /* Timer stuff */
  171. #define MAXDELTAT (0.1)
  172. EXTERN long ticks_per_sec;
  173. EXTERN double deltaT;
  174. EXTERN double absT;
  175. EXTERN double fps;
  176.  
  177. #ifdef WIN32
  178. EXTERN _int64 last_ticks;
  179. #else
  180. EXTERN int last_ticks;
  181. #endif
  182.  
  183. /* Stuff for the stars */
  184. #define NSTARS (2000)
  185. EXTERN struct
  186. {
  187.   double x,y,z; /* Star coords */
  188.   double mag;  /* Star magnitude */
  189.   double bright; /* Point brightness */
  190.   double bright2; /* Brightness for sparse starfield */
  191. }
  192. star[NSTARS];
  193.  
  194. EXTERN int star_list;  /* Starfield display lists */
  195. EXTERN int star_list_sparse;
  196. EXTERN int star_list_dense;
  197. EXTERN int starfield; /* Display starfield? */
  198.  
  199. EXTERN int paused;  /* True if game paused */
  200.  
  201. /* Whether or not to display the HUD */
  202. EXTERN int drawhud;
  203.  
  204. /* Whether or not to show the frame rate */
  205. EXTERN int showfps;
  206.  
  207. /* Stuff for the message console */
  208. #define CONSLINES (10)
  209. #define CONSBUF (128)
  210. #define CONSAGE (3.0)
  211. #define CONSHEIGHT (10)
  212. EXTERN struct
  213. {
  214.   double age[CONSLINES]; /* How long each line has been on screen */
  215.   int next;  /* index of next line to use */
  216.   char buf[CONSLINES][CONSBUF]; /* messages */
  217. }
  218. console;
  219.  
  220. /* Gravity stuff */
  221. EXTERN int gravity; /* Is gravity on or off? */
  222. #define G (0.025)
  223. #define RMIN (2.0)
  224.  
  225. /* Allow full stop? */
  226. EXTERN int fullstop; /* True if full stop allowed */
  227.  
  228. /* Regular warp or super warp engines? */
  229. EXTERN int superwarp;
  230.  
  231. /* Stuff for missiles */
  232. #define NMSLS (32)
  233. #define MSL_EXPIRE (5.0)
  234. #define MSL_IDLE (0.2) /* Min seconds between missiles */
  235. #define TARGET_MSL_IDLE (2.0) /* Same for targets */
  236. #define MSL_MIN_AGE (0.1) /* Time before msl can hit something */
  237. #define MSL_VEL (0.5)
  238. EXTERN struct
  239. {
  240.   double pos[3]; /* Missile position */
  241.   double vel[3]; /* Missile velocity */
  242.   double age;  /* Missile age (0 == not in use) */
  243.   int friendly; /* True if player launced missile */
  244.   int weapon;  /* What type of weapon this is */
  245.   int owner;  /* Who owns this missile (-1 if player) */
  246. }
  247. msl[NMSLS];
  248.  
  249. /* Space junk */
  250. EXTERN int junk;   /* True to draw space junk */
  251.  
  252. /* Stuff for explosions */
  253. #define NBOOMS (32)
  254. #define BOOM_TIME (1.0) /* Length of explosion in seconds */
  255. EXTERN int palette_flash; /* True to flash whole screen */
  256. EXTERN struct
  257. {
  258.   double pos[3]; /* Explosion position */
  259.   double age;  /* Explosion age (0 == not in use) */
  260.   int light;  /* Index of corresponding light[] entry */
  261.   double angle; /* Angle to rotate boom */
  262.   double size; /* Size of this boom */
  263. }
  264. boom[NBOOMS];
  265.  
  266. #define X .525731112119133606
  267. #define Z .850650808352039932
  268.  
  269. #ifdef ALLOCATE
  270. double icos_data[12][3] =
  271. {
  272.   {
  273.     -X, 0, Z}
  274.   , {
  275.     X, 0, Z}
  276.   , {
  277.     -X, 0, -Z}
  278.   , {
  279.     X, 0, -Z}
  280.   , {
  281.     0, Z, X}
  282.   , {
  283.     0, Z, -X}
  284.   ,
  285.   {
  286.     0, -Z, X}
  287.   , {
  288.     0, -Z, -X}
  289.   , {
  290.     Z, X, 0}
  291.   , {
  292.     -Z, X, 0}
  293.   , {
  294.     Z, -X, 0}
  295.   , {
  296.     -Z, -X, 0}
  297. }
  298. ;
  299. #else
  300. extern double icos_data[12][3];
  301. #endif
  302.  
  303. #ifdef ALLOCATE
  304. int icos_index[20][3] =
  305. {
  306.   {
  307.     0, 4, 1}
  308.   , {
  309.     0, 9, 4}
  310.   , {
  311.     9, 5, 4}
  312.   , {
  313.     4, 5, 8}
  314.   , {
  315.     4, 8, 1}
  316.   ,
  317.   {
  318.     8, 10, 1}
  319.   , {
  320.     8, 3, 10}
  321.   , {
  322.     5, 3, 8}
  323.   , {
  324.     5, 2, 3}
  325.   , {
  326.     2, 7, 3}
  327.   ,
  328.   {
  329.     7, 10, 3}
  330.   , {
  331.     7, 6, 10}
  332.   , {
  333.     7, 11, 6}
  334.   , {
  335.     11, 0, 6}
  336.   , {
  337.     0, 1, 6}
  338.   ,
  339.   {
  340.     6, 1, 10}
  341.   , {
  342.     9, 0, 11}
  343.   , {
  344.     9, 11, 2}
  345.   , {
  346.     9, 2, 5}
  347.   , {
  348.     7, 2, 11}
  349. }
  350. ;
  351. #else
  352. extern int icos_index[20][3];
  353. #endif
  354.  
  355. EXTERN double boom_data[12][3];
  356.  
  357. #ifdef ALLOCATE
  358. double boom_color[12][4] =
  359. {
  360.   {
  361.     0.75, 0.75, 0.0, 1.0}
  362.   , {
  363.     0.75, 0.75, 0.0, 1.0}
  364.   , {
  365.     0.75, 0.75, 0.0, 1.0}
  366.   ,
  367.   {
  368.     0.75, 0.75, 0.0, 1.0}
  369.   , {
  370.     0.75, 0.75, 0.0, 1.0}
  371.   , {
  372.     0.75, 0.75, 0.0, 1.0}
  373.   ,
  374.   {
  375.     0.75, 0.75, 0.0, 1.0}
  376.   , {
  377.     0.75, 0.75, 0.0, 1.0}
  378.   , {
  379.     0.75, 0.75, 0.0, 1.0}
  380.   ,
  381.   {
  382.     0.75, 0.75, 0.0, 1.0}
  383.   , {
  384.     0.75, 0.75, 0.0, 1.0}
  385.   , {
  386.     0.75, 0.75, 0.0, 1.0}
  387. }
  388. ;
  389. #else
  390. extern double boom_color[12][4];
  391. #endif
  392.  
  393. /* Sound stuff */
  394. EXTERN int sound;  /* True for sound effects */
  395.  
  396. /* Constants */
  397. enum sounds {
  398.   SOUND_FIRE,
  399.   SOUND_BOOM,
  400.   SOUND_COMM,
  401.   NSOUNDS
  402. }
  403. ;
  404.  
  405. /* Functions */
  406. int InitSound (void);
  407. int PlayAudio (enum sounds);
  408. void FinishSound (void);
  409.  
  410. EXTERN int show_names; /* True to show names of things */
  411.  
  412. /* Lights stuff */
  413. #define NLIGHTS GL_MAX_LIGHTS
  414.  
  415. EXTERN struct
  416. {
  417.   float pos[4]; /* Light position */
  418.   float color[3]; /* Light color */
  419.   double age;  /* Age of light (0 == not in use) */
  420.   int gl_num;  /* GL number of light */
  421. }
  422. light[NLIGHTS];
  423.  
  424. /* Target stuff */
  425. #define NTARGETS (32)
  426. EXTERN struct
  427. {
  428.   double pos[3];  /* Target position */
  429.   double vel[3];  /* Target velocity */
  430.   double view[3];  /* Viewing direction */
  431.   double up[3];  /* Up vector */
  432.   double right[3]; /* Right vector */
  433.   double age;   /* Target age (0 == unused) */
  434.   double range2;  /* Distance from player */
  435.   double move_forward, move_backward,
  436.   move_up, move_down,
  437.   move_pitchleft, move_pitchright,
  438.   move_left, move_right; /* Motion */
  439.   double msl_idle; /* How long laucher has been idle */
  440.   char name[32];  /* Target name */
  441.   int list;   /* Target display list */
  442.   int score;   /* Points for destroying this target */
  443.   int model;   /* Index of target's model */
  444.   int strategy;  /* This target's strategy for ThinkTarget() */
  445.   int hidden;   /* True if hidden */
  446.   int invisible;   /* True if invisible */
  447.   int friendly;  /* True if on our side */
  448.   double shields;  /* Shield strength */
  449.   double maxshields; /* Maximum shields */
  450.   double shieldregen; /* How fast shields regenerate */
  451.   double turnrate; /* How fast it can turn */
  452.   double maxvel;  /* How fast it can accelerate */
  453.   int weapon;   /* Current weapon */
  454. }
  455. target[NTARGETS];
  456.  
  457. #define TARGDIST (0.02)
  458. #define TARGDIST2 (TARGDIST * TARGDIST)
  459. #define MINFIREDIST (1.0 / KM_TO_UNITS1)
  460. #define MINFIREDIST2 (MINFIREDIST * MINFIREDIST)
  461. #define MAXFIREDIST (3000.0 / KM_TO_UNITS1)
  462. #define MAXFIREDIST2 (MAXFIREDIST * MAXFIREDIST)
  463. #define TARG_MAXRANGE (50000.0 / KM_TO_UNITS1)
  464. #define TARG_MAXRANGE2 (TARG_MAXRANGE * TARG_MAXRANGE)
  465.  
  466. /* Radar stuff */
  467. EXTERN double radarR, radarCOS, radarSIN;
  468. EXTERN struct
  469. {
  470.   int center[2];  /* Center of radar on screen, in pixels */
  471.   double fcenter[2]; /* Floating version */
  472.   int radius;   /* Radius of screen, in pixels */
  473.   double fradius;  /* Floating version */
  474.   int list;   /* Display list */
  475. }
  476. radar;
  477.  
  478. /* Other HUD stuff */
  479. EXTERN struct
  480. {
  481.   double throt_min[2]; /* Coords of throttle display */
  482.   double throt_mid[2];
  483.   double throt_max[2];
  484.   double targ_name[2]; /* Coords of target name */
  485.   double targ_range[2]; /* Target range */
  486.   double vel[2];   /* Player velocity */
  487.   double shields_min[2]; /* Player shields */
  488.   double shields_max[2];
  489.   double weapon[2];  /* Weapon name */
  490.   double targshields_min[2]; /* Target shields */
  491.   double targshields_max[2];
  492.   double waypoint[2];  /* Current waypoint */
  493. }
  494. hud;
  495.  
  496. /* Shield stuff */
  497. #define SHIELD_REGEN (5.0)
  498.  
  499. /* Texture stuff */
  500. EXTERN GLubyte planet_tex[256][256][3]; /* Planet texture */
  501. EXTERN int planet_list;
  502.  
  503. /* Screen shot stuff */
  504. EXTERN int screen_shot_num;
  505.  
  506. /* Planet stuff */
  507. #define NPLANETS (32)
  508. EXTERN struct
  509. {
  510.   int hidden;   /* Don't draw */
  511.   double dist;  /* Distance from primary */
  512.   double pos[3];  /* Planet position */
  513.   double theta;  /* Solar angle */
  514.   double radius;  /* Planet size */
  515.   double oblicity; /* Oblicity (inclination from orbital plane) */
  516.   double radius2;  /* Radius squared */
  517.   double range2;  /* Distance^2 from player */
  518.   double absrange2; /* Absolute range (ignoring radius) */
  519.   double mass;  /* Mass, for gravity calculation */
  520.   float color[3];  /* Average color */
  521.   int texid;   /* Texture id */
  522.   GLubyte tex[256][256][3]; /* Texture */
  523.   char texfname[32]; /* Name of texture file */
  524.   char name[32];  /* Planet name */
  525.   int is_moon;  /* True if this is a moon */
  526.   int primary;  /* Index of primary if moon */
  527.   int list20;   /* Display lists */
  528.   int list80;
  529.   int list320;
  530.   int orbitlist;  /* Display list for orbit */
  531.   double angvel;  /* Angular velocity in degrees per second */
  532.   int custom;   /* True if customized */
  533. }
  534. planet[NPLANETS];
  535.  
  536. #define ORBIT_SECTORS (360)
  537.  
  538. /* Planet detail levels */
  539. EXTERN int slices0, stacks0,
  540. slices1, stacks1,
  541. slices2, stacks2;
  542.  
  543. EXTERN int textures; /* True to draw textures */
  544.  
  545. EXTERN int realdistances; /* True for correct planet distances */
  546.  
  547. EXTERN int draw_orbits; /* True to draw orbits */
  548. EXTERN int orbit;   /* True to make planets orbit */
  549. EXTERN double compression; /* Time compression */
  550.  
  551. EXTERN int first_vertex;  /* For texture fixing */
  552. EXTERN double maxtdiff;
  553.  
  554. /* Unit conversions */
  555. #define KM_TO_UNITS1 (6000.0) /* Radii */
  556. #define KM_TO_UNITS2 (6000.0 / 1000000.0) /* Distances */
  557.  
  558. /* Model stuff */
  559. #define NMODELS (32)
  560. EXTERN struct
  561. {
  562.   int in_use;   /* True if in use */
  563.   char name[32];  /* Model name */
  564.   int list;   /* Display list */
  565.   double lobound[3];
  566.   double hibound[3]; /* Coords of bounding box */
  567.   double radius;
  568.   double radius2;  /* Radius of bounding sphere */
  569. }
  570. model[NMODELS];
  571.  
  572. /* Mission stuff */
  573. EXTERN struct
  574. {
  575.   double cursor[3];
  576.   double player[3];
  577.   char briefing[4096];
  578.   char fn[128];
  579.   int verbose;
  580. }
  581. mission;
  582.  
  583. /* Strategies */
  584. #define STRAT_DONOTHING (0)
  585. #define STRAT_SIT1 (1)
  586. #define STRAT_SIT2 (2)
  587. #define STRAT_SIT3 (3)
  588. #define STRAT_SIT4 (4)
  589. #define STRAT_HUNT1 (5)
  590. #define STRAT_HUNT2 (6)
  591. #define STRAT_HUNT3 (7)
  592. #define STRAT_HUNT4 (8)
  593.  
  594. /* Message stuff (messages in center of screen) */
  595. EXTERN struct
  596. {
  597.   char text[4096]; /* Message text */
  598.   int len;   /* Length in pixels */
  599.   double age;   /* Age in seconds */
  600. }
  601. message;
  602.  
  603. /* Max time to keep message on screen */
  604. #define MSG_MAXAGE (30)
  605.  
  606. /* Rings stuff */
  607. #define NRINGS (4)
  608. #define MAX_RING_RANGE (200.0 * 200.0)
  609. #define RING_SECTORS (48)
  610. EXTERN struct
  611. {
  612.   int primary; /* Which planet */
  613.   int list;  /* Display list */
  614.   int texid;  /* Texture id */
  615.   GLubyte tex[256][8][4]; /* Texture */
  616.   double r1, r2; /* Inner, outer radii */
  617.   char fn[64]; /* Texture file name */
  618. }
  619. ring[NRINGS];
  620.  
  621. EXTERN int rings;  /* True to draw rings */
  622. EXTERN int ring_sectors; /* Sectors per ring */
  623.  
  624. /* Event stuff */
  625. #define NEVENTS (32)
  626. #define ACTIONS_PER_EVENT (64)
  627. EXTERN struct
  628. {
  629.   char name[32]; /* Event name */
  630.   int pending; /* True if hasn't happened yet */
  631.   int enabled; /* True if enabled */
  632.   int trigger; /* Event type */
  633.   int ivalue;  /* Event values */
  634.   double fvalue;
  635.   char *cvalue;
  636.   double pos[3]; /* Event position */
  637.  
  638.   /* Actions */
  639.   struct
  640.   {
  641.     int active;
  642.     int action;  /* Event actions */
  643.     int ivalue;
  644.     double fvalue;
  645.     char *cvalue;
  646.   }
  647.   action[ACTIONS_PER_EVENT];
  648. }
  649. event[NEVENTS];
  650.  
  651. /* Event triggers */
  652. #define EVENT_NULL (0)
  653. #define EVENT_APPROACH (1)
  654. #define EVENT_DESTROY (2)
  655. #define EVENT_SCORE (3)
  656. #define EVENT_ALARM (4)
  657. #define EVENT_DEPART (5)
  658. #define EVENT_TRUE (6)
  659. #define EVENT_STOPNEAR (7)
  660. #define EVENT_SHIELDS (8)
  661.  
  662. /* Event actions */
  663. #define EVENT_MESSAGE (10)
  664. #define EVENT_HIDE (11)
  665. #define EVENT_UNHIDE (12)
  666. #define EVENT_ENABLE (13)
  667. #define EVENT_DISABLE (14)
  668. #define EVENT_LOADMISSION (15)
  669. #define EVENT_STOP (16)
  670. #define EVENT_BOOM (17)
  671. #define EVENT_FLASH (18)
  672. #define EVENT_MOVEOBJECT (19)
  673. #define EVENT_MOVEPLAYER (20)
  674. #define EVENT_MOVEPLANET (21)
  675. #define EVENT_HIDEPLANET (22)
  676. #define EVENT_UNHIDEPLANET (23)
  677. #define EVENT_BETRAY (24)
  678.  
  679. /* Target lock stuff */
  680. #define LOCK_ENEMY (0)
  681. #define LOCK_FRIENDLY (1)
  682. #define LOCK_PLANET (2)
  683. EXTERN struct
  684. {
  685.   int target;  /* Locked target, -1 if none */
  686.   int type;  /* Target type */
  687. }
  688. lock;
  689.  
  690. /* Weapons stuff */
  691. #define NWEAPONS (10)
  692. EXTERN struct
  693. {
  694.   char name[32]; /* Name of weapon */
  695.   double yield; /* How much damage it does */
  696.   double speed; /* How fast it goes */
  697.   double idle; /* Time between shots, in seconds */
  698.   double expire; /* How long till it dissipates */
  699.   int renderer; /* How to draw */
  700.   float color[3]; /* Color */
  701.   double range2; /* Range of weapon squared */
  702. }
  703. weapon[NWEAPONS];
  704. #define NPLAYER_WEAPONS (4)
  705.  
  706. EXTERN int warpspeed; /* True if using warp engines */
  707.  
  708. /* Mouse stuff */
  709. EXTERN struct
  710. {
  711.   int left, right, up, down;
  712.   int x, y;
  713.   int flipx;
  714.   int flipy;
  715. }
  716. mouse;
  717. EXTERN int mouse_control;
  718.  
  719. /* Video mode stuff */
  720. EXTERN int fullscreen;  /* To use glutFullScreen() */
  721. EXTERN char gamemode[64]; /* To use glutGameMode() */
  722.  
  723. /* Game state stuff */
  724. #define STATE_INIT (1)
  725. #define STATE_NORMAL (2)
  726. #define STATE_DEAD1 (3)
  727. #define STATE_DEAD2 (4)
  728. #define STATE_LOADGAME (5)
  729. #define STATE_GETTEXT (6)
  730. EXTERN int state;  /* Game state */
  731.  
  732. /* Stuff for loads and saves */
  733. #define NSAVES (10)
  734. EXTERN struct
  735. {
  736.   char fn[128]; /* Mission file name */
  737.   int time; /* Time stamp */
  738. }
  739. save[NSAVES];
  740. EXTERN int nsaves;
  741.  
  742. /* Waypoints */
  743. #define NWAYPOINTS (32)
  744. EXTERN struct
  745. {
  746.   double pos[3];  /* Waypoint location */
  747. }
  748. waypoint[NWAYPOINTS];
  749. EXTERN int nwaypoints; /* Number of active waypoints */
  750.  
  751. /* 
  752.  *  Network stuff
  753.  */
  754.  
  755. #ifndef WIN32
  756. #define SOCKET int
  757. #endif
  758.  
  759. /* Undef this to use ASCII packets only.  Good if the two machines
  760.    don't use IEEE floats */
  761. #define BINARYPACKETS
  762.  
  763. #define ORBIT_PORT (2061)
  764.  
  765. /* Timing stuff */
  766. #define MAXCLIENTIDLE (60.0)
  767. #define MAXSERVERIDLE (120.0)
  768. #define PINGINTERVAL (20.0)
  769. #define CLIENTPOSINTERVAL (0.33)
  770. #define ROLLCALLINTERVAL (30.0)
  771.  
  772. #define POSNINTERVALSMALL (0.33)
  773. #define POSNINTERVALMEDIUM (0.66)
  774. #define POSNINTERVALLARGE (1.0)
  775. #define PINGFAST (100.0)
  776. #define PINGSLOW (400.0)
  777.  
  778. EXTERN int am_server; /* True if I'm a server */
  779. EXTERN int am_client; /* True if I'm a client */
  780.  
  781. void SendASCIIPacket (SOCKET socket, char *fmt, ...);
  782. void SendBinaryPacket (SOCKET socket, char *fmt, ...);
  783.  
  784. /* Stuff to remember about each client */
  785. #define NCLIENTS (8)
  786. EXTERN struct
  787. {
  788.   int active; /* True if the client is active */
  789.   int is_me; /* True if this client is me */
  790.   int target; /* Index of target structure for this client */
  791.   SOCKET socket; /* This client's socket */
  792.   double ping; /* Ping time for this client */
  793.   double posninterval; /* How often to send position reports to this client */
  794.   struct
  795.   {
  796.     double idle; /* How long since we heard from this client */
  797.     double ping; /* How long since we pinged this client */
  798.     double posn[NCLIENTS]; /* How long since we reported this client's
  799.         position to each other client */
  800.     double rollcall; /* Time since we sent a roll call to this client */
  801.   }
  802.   timer;
  803.   char pkt[1024]; /* Packet currently being received */
  804.   int ptr; /* Index of next byte in pkt */
  805.   int state; /* Binary packet state */
  806.   int remain; /* Bytes remaining in this binary packet */
  807.   int frags; /* Number of kills */
  808.   char ip[32]; /* IP address of client */
  809. }
  810. client[NCLIENTS];
  811.  
  812. /* Some server stuff */
  813. EXTERN struct
  814. {
  815.   SOCKET listening_socket; /* Socket server listens on */
  816.   int client;   /* Number of server's client */
  817.   int port;   /* Port to listen on */
  818.   char ip[32];  /* My IP address */
  819. }
  820. server;
  821.  
  822. /* Network game flags */
  823. #define FLAG_GRAVITY (0x01)
  824. #define FLAG_FLIGHTMODEL (0x02)
  825. #define FLAG_FULLSTOP (0x04)
  826. #define FLAG_REALDISTANCES (0x08)
  827. #define FLAG_ORBIT (0x10)
  828.  
  829. EXTERN struct
  830. {
  831.   SOCKET socket;  /* Socket client uses to talk to server */
  832.   char pkt[1024];  /* Packet being received */
  833.   int ptr;  /* Next byte in pkt */
  834.   int state;  /* Binary packet state */
  835.   int remain;  /* Bytes remaining in this binary packet */
  836.   int client;  /* Our client number */
  837.   int urgent;  /* We have an urgent position report */
  838.   struct
  839.   {
  840.     double server; /* Time since we heard from server */
  841.     double pos; /* Time since we last reported position */
  842.   }
  843.   timer;
  844. }
  845. clientme;
  846.  
  847. /* States for binary packets */
  848. #define NETSTATE_MAGIC (1) /* Waiting for Magic byte */
  849. #define NETSTATE_SIZE (2) /* Waiting for size byte */
  850. #define NETSTATE_PACKET (3) /* Reading packet */
  851.  
  852. #define NET_MAGIC (0x56) /* Magic start-of-packet byte */
  853.  
  854. /* Binary packet types.  HIGH BIT MUST BE SET! */
  855. #define PKT_POSS (0x80)  /* Short position */
  856. #define PKT_POSL (0x81)  /* Long position */
  857. #define PKT_POSU (0x82)  /* Urgent position */
  858. #define PKT_POSN (0x83)  /* Regular position */
  859. #define PKT_PLAN (0x84)  /* Planet position */
  860. #define PKT_VCNT (0x85)  /* Vacancy report */
  861. #define PKT_PING (0x86)  /* Ping to get latency */
  862.  
  863. EXTERN double recv_bps, xmit_bps; /* Receive, transmit rates */
  864. EXTERN int recv_bytes, xmit_bytes; /* Bytes received/sent */
  865.  
  866. /* Stuff for reading in text */
  867. #define TEXTSIZE (128)
  868. EXTERN struct
  869. {
  870.   int yes;   /* True if typing */
  871.   char buf[TEXTSIZE]; /* Buffer */
  872.   int index;   /* Index into buffer */
  873.   char prompt[32]; /* Prompt */
  874.   void (*func)(void);  /* Function to call when done */
  875. }
  876. text;
  877.